#include <windows.h>
#include <Iphlpapi.h>
#include <stdio.h>
#include <tchar.h>

#include <stdlib.h>  
#include <assert.h>  
#include <io.h>
#include <direct.h>



#include <wincrypt.h>

#include <string>
#include <iostream>
using namespace std;

#pragma once

#pragma comment(lib,"Iphlpapi")

#define DFP_GET_VERSION 0x00074080
#define DFP_RECEIVE_DRIVE_DATA 0x0007c088
// values for IDEREGS.bCommandReg
#define IDE_ATAPI_IDENTIFY 0xA1
#define IDE_ATA_IDENTIFY 0xEC
#define IDENTIFY_BUFFER_SIZE 512
void getMac(char *szMac);
void GetCpuID(char *szCpuid);
int main(int argc, char **argv)
{
	//CPUID
	char szCpuidchar[256] = {0};
	GetCpuID(szCpuidchar); 
	printf("ID1:\t%s\n",szCpuidchar);
	//MACID
	char bufMac[256] = {'\0'};
	getMac(bufMac);
	printf("ID2:\t%s\n",bufMac);
	printf("Press Enter to exit...\n");
	getchar();
	return 0;
}
void getMac(char *szMac)
{
	ULONG BufferLength = 0;
	BYTE* pBuffer = 0;
	if( ERROR_BUFFER_OVERFLOW == GetAdaptersInfo( 0, &BufferLength ))
	{
		// Now the BufferLength contain the required buffer length.
		// Allocate necessary buffer.
		pBuffer = new BYTE[ BufferLength ];
	}
	else
	{
		// Error occurred. handle it accordingly.
	}

	// Get the Adapter Information.
	PIP_ADAPTER_INFO pAdapterInfo =
		reinterpret_cast<PIP_ADAPTER_INFO>(pBuffer);
	GetAdaptersInfo( pAdapterInfo, &BufferLength );

	// Iterate the network adapters and print their MAC address.
	while( pAdapterInfo )
	{
		if (pAdapterInfo->Address[0] == 0 &&
			pAdapterInfo->Address[1] == 0 &&
			pAdapterInfo->Address[2] == 0 &&
			pAdapterInfo->Address[3] == 0 &&
			pAdapterInfo->Address[4] == 0 &&
			pAdapterInfo->Address[5] == 0)
		{
			pAdapterInfo = pAdapterInfo->Next;
		}
		else
		{
			// Assuming pAdapterInfo->AddressLength is 6.
			sprintf_s(szMac,256,"%02x%02x%02x%02x%02x%02x",
				pAdapterInfo->Address[0],
				pAdapterInfo->Address[1],
				pAdapterInfo->Address[2],
				pAdapterInfo->Address[3],
				pAdapterInfo->Address[4],
				pAdapterInfo->Address[5]);

			break;
		}
	}
	if (pBuffer != NULL)
		delete []pBuffer;
}
void GetCpuID(char *szCpuid)   
{  


	char szCpu[16]  = { 0 };  
	unsigned int uCpuID     = 0U; 


	__asm{  
		mov eax, 0  
			cpuid  
			mov dword ptr szCpu[0], ebx  
			mov dword ptr szCpu[4], edx  
			mov dword ptr szCpu[8], ecx  
			mov eax, 1  
			cpuid  
			mov uCpuID, edx  
	}  
	sprintf_s(szCpuid,20,"%u",uCpuID);
}